﻿Imports QL_GioiThieu_NhaThue.sqlDataProvider
Imports System.Data.SqlClient
Public Class Backup_RestoreDuLieuDAO
    Public Shared Sub Backup(ByVal paraDulieu As SqlParameter, ByVal paraPath As SqlParameter)

        Dim cn As SqlConnection = New SqlConnection(_strConnectionString)
        Try
            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "usp_Backup"
            cmd.Connection = cn
            cmd.Parameters.Add(paraDulieu)
            cmd.Parameters.Add(paraPath)

            cn.Open()
            cmd.ExecuteNonQuery()
            cn.Close()
        Catch ex As Exception
            MessageBox.Show("Phát hiện lỗi!" + Environment.NewLine + ex.Message, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cn.State = ConnectionState.Open Then
                cn.Close()
            End If
        End Try
        
    End Sub

    Public Shared Sub Restore(ByVal paraDulieu As SqlParameter, ByVal paraPath As SqlParameter)

        Dim cnnStr As String = "Data Source=.\SQLEXPRESS;Initial Catalog= master ;Integrated Security=True"

        Dim sql = "Restore Database @database From Disk = @path "

        Dim cn As SqlConnection = New SqlConnection(cnnStr)
        Try
            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.Text
            cmd.CommandText = sql
            cmd.Connection = cn
            cmd.Parameters.Add(paraDulieu)
            cmd.Parameters.Add(paraPath)

            cn.Open()
            cmd.ExecuteNonQuery()
            cn.Close()
        Catch ex As Exception
            MessageBox.Show("Phát hiện lỗi!" + Environment.NewLine + ex.Message, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cn.State = ConnectionState.Open Then
                cn.Close()
            End If
        End Try
        
    End Sub


End Class
